package com.weakteam.orderonline.adminconsole.gwt.client.widget;


import com.google.gwt.user.client.ui.HTML;
import com.weakteam.orderonline.adminconsole.gwt.client.domain.Category;
import com.weakteam.orderonline.adminconsole.gwt.client.util.uploader.file.FileUtil;



/**
 * Created by Max on 02.04.2014.
 */
public class MenuCategoryBox extends HTML {

    private Category category;

    private Boolean selected;

    public MenuCategoryBox(Category category) {
        this.category = category;
        this.selected = false;
        this.setEnabled(category.getEnabled());
        this.setData(category);
        this.setStyleName("category-item");
    }

    public Boolean isSelected() {
        return selected;
    }
    public Category getCategory(){
        return this.category;
    }
    public int getCategoryId() {
        return this.category.getId();
    }
    public void setCategoryOrder(int index) {
        this.category.setOrder(index);
    }


    public void setData(Category data) {
        String html = "<div>"+ data.getName()+"</div>" +
                      "<img onmousedown=\"return false\" class=\"category-item\"" +
                      "src=\""+ FileUtil.getImageURL(data.getImage())+"\">";
        this.setHTML(html);
    }

    public void setSelected(Boolean selected) {
        this.selected = selected;
        if (selected) {
            this.addStyleName("content-item-selected");
        } else {
            this.removeStyleName("content-item-selected");
        }
    }

    public void setEnabled(Boolean enabled) {
        if (enabled) {
            this.removeStyleName("content-item-disabled");
        } else {
            this.addStyleName("content-item-disabled");
        }
    }


}